package auth

type AuthEntity interface {
	IsEnabled(Role) bool
	IsAdmin() bool
	IsTeacher() bool
	IsStudent() bool
	IsSelf(string) bool

	GetUsername() string
	GetRole() Role
}

func NewAuthEntity(username string, role Role) AuthEntity {
	return &Auth{
		Username: username,
		Role:     role,
	}
}

func (a *Auth) IsEnabled(role Role) bool {
	return a.Role&role != 0
}

func (a *Auth) IsAdmin() bool {
	return a.Role&RoleAdmin != 0
}

func (a *Auth) IsTeacher() bool {
	return a.Role&RoleTeacher != 0
}

func (a *Auth) IsStudent() bool {
	return a.Role&RoleStudent != 0
}

func (a *Auth) IsSelf(username string) bool {
	return a.Username == username
}

func (a *Auth) GetUsername() string {
	return a.Username
}

func (a *Auth) GetRole() Role {
	return a.Role
}

func (a *Auth) GetAuthInfo() *Auth {
	return a
}
